package es.juanc.threads;

public class HilosSyncTest {

	/**
	 * @param args
	 */
	public static void main(String[] args) {

		ClaseSync s1 = new ClaseSync( "pepe" );
		ClaseSync s2 = new ClaseSync( "paco" );

		MyRunable h1 = new MyRunable( s1 );
		h1.start();

		MyRunable h2 = new MyRunable( s2 );
		h2.start();

		System.out.println( "Fin ..." );
	}
}

class ClaseSync {

	//private static String name;
	private String name;

	public ClaseSync( String name ) {
		this.name = name;
	}

	//public static synchronized void exec() {
	public synchronized void exec() {
		System.out.println( "Soy " + name );
	}
}

class MyRunable extends Thread {

	private ClaseSync sync;

	public MyRunable( ClaseSync sync ) {
		this.sync = sync;
	}

	@Override
	public void run() {
		sync.exec();
	}
}